package com.fenxiao.dingshi.service;

import java.util.List;

import org.apache.poi.hssf.record.formula.functions.FinanceFunction;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.fenxiao.mytask.entity.UserTask;
@Component
public class Shenheshibai implements IShenheshibai {
	@Autowired
	private SessionFactory sessionFactory;
	
			 @Scheduled(cron="0 0 0 * * ?")   //每5秒执行一次   
			public void name() {
				 Session session=sessionFactory.openSession();
				 String hql = "select u.taskId from UserTask u where u.taskStatus=1" ;
				 Query query=session.createQuery(hql);
				 try{
					List list=query.list();
					System.err.println("获取的ID+------"+list);
					if(list!=null&&list.size()!=0){
						for (int i = 0; i < list.size(); i++) {
							Long usertaskid = (Long) list.get(i);
							String hql1 = "Update UserTask u set u.taskStatus=3 where u.taskStatus=1 and u.taskId="+usertaskid;
							session.createQuery(hql1).executeUpdate();
							String hql2 = "Update Task t set t.taskRemainderNumber=1+t.taskRemainderNumber where t.taskId="+usertaskid;
							session.createQuery(hql2).executeUpdate();
						}
					
							
						}
					
	
					}catch (Exception e) {
					   e.printStackTrace();
					}
					}	
}
	
